package edu.fiu.kdrg.mqlminer.sql;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;

import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;

public class Main {

	public static void main(String[] args) throws Exception {

		// Create an input character stream from standard input
		InputStream br = new FileInputStream(new File("test.sql"));
		ANTLRInputStream input = new ANTLRInputStream(br);
		MySQLLexer lexer = new MySQLLexer(input); // create lexer
		// Create a buffer of tokens between the lexer and parser
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		MySQLParser parser = new MySQLParser(tokens); // create parser
		MySQLParser.program_return r = null;
		r = parser.program(); // parse rule expr and get return structure
		CommonTree t = (CommonTree) r.getTree();// extract AST
		if (!t.isNil()) {
			System.out.println(t.toStringTree());
			return;
		}
		//

		int ncount = t.getChildCount();
		for (int i = 0; i < ncount; i++)
			System.out.println(t.getChild(i).toStringTree());
		// System.out.println(t.toStringTree()); // print out
		// Create a stream of nodes from a tree
		CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
		System.out.println();

	}
}
